package com.guigu.www.luolujin.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.luolujin.Service.LljTemplateKeepService;
import com.guigu.www.mapper.TemplateKeepMapper;
import com.guigu.www.pojo.FoodZong;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.pojo.TemplateKeep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者 罗露金
 */
@Service
public class LljTemplateKeepServiceImpl implements LljTemplateKeepService {
    @Autowired
    TemplateKeepMapper mapper;
    @Override
    public PageVo<TemplateKeep> pageTemKeep(Integer pageNum, Integer pageSize, String tempKeepName) {
        QueryWrapper<TemplateKeep> wrapper = new QueryWrapper<>();
        wrapper.like("temp_keep_name",tempKeepName);
        Page<TemplateKeep> page = new Page<>(pageNum, pageSize);
        IPage<TemplateKeep> iPage = mapper.selectPage(page, wrapper);
        PageVo<TemplateKeep> pageVo = new PageVo<>();
        pageVo.setRows(iPage.getRecords());
        pageVo.setTotal(iPage.getTotal());
        return pageVo;
    }

    @Override
    public void insertTemKeep(TemplateKeep templateKeep) {
        mapper.insert(templateKeep);
    }

    @Override
    public void updateTemKeep(TemplateKeep templateKeep) {
        mapper.updateById(templateKeep);
    }

    @Override
    public void deleteTemKeep(int tempKeepId) {
        mapper.deleteById(tempKeepId);
    }

    @Override
    public TemplateKeep selectById(int tempKeepId) {
        return mapper.selectById(tempKeepId);
    }

    @Override
    public void upTemKeep(Integer tempKeepId, Integer tempWhoState) {
        TemplateKeep templateKeep = new TemplateKeep();
        templateKeep.setTempKeepId(tempKeepId);
        templateKeep.setTempWhoState(tempWhoState);
        mapper.updateById(templateKeep);
    }

    @Override
    public List<TemplateKeep> queryAll() {
        QueryWrapper<TemplateKeep> wrapper = new QueryWrapper<>();
        wrapper.eq("temp_who_state ",0);
        return mapper.selectList(wrapper);
    }
}
